package com.wutianyi.db;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;

public class BoneCPMain {
	public static void main(String[] args) throws SQLException {

		BoneCP connectionPool = null;
		Connection connection = null;
		try {

		} catch (Exception e) {

		}
		try {
			BoneCPConfig config = new BoneCPConfig();
			config.setJdbcUrl("jdbc:mysql://localhost:3306/test?characterEncoding=utf8");
			config.setUsername("root");
			config.setPassword("860728");
			config.setMinConnectionsPerPartition(5);
			config.setMaxConnectionsPerPartition(10);
			config.setPartitionCount(1);
			connectionPool = new BoneCP(config);
			connection  = connectionPool.getConnection();
			Statement tm = connection.createStatement();
			tm.execute("insert into example1(n)values('吴天翼')");
			tm.close();
			connection.close();
			connection =  connectionPool.getConnection();
			
			if(null != connection) {
				System.out.println("Connection successful!");
				Statement stmt = connection.createStatement();
				ResultSet rs = stmt.executeQuery("SELECT * FROM example1"); // do something with the connection.
				while(rs.next()){
					System.out.println(rs.getString("n")); // should print out "1"'
				}
			}
			connectionPool.shutdown();
		} catch(Exception e) {
			
		} finally {
			if(null != connection) {
				connection.close();
			}
		}
		
	}
}
